// Then the target.*.rustflags value
let target = build_config.requested_target.as_ref().unwrap_or(&build_config.host_triple);
let key = format!("target.{}.{}", target, name);
- if let Some(args) = config.get_list(&key)? {
+ let list = config.get_list(&key);
+ if let Ok(Some(args)) = list {
let args = args.val.into_iter().map(|a| a.0);
return Ok(args.collect());
}
+ let string = config.get_string(&key);
+ if let Ok(Some(arg)) = string {
+ return Ok(arg.val.split(' ').map(str::to_string).collect());
+ }
+ if list.is_err() && string.is_err() {
+ if let Some(value) = config.values()?.get(&key) {
+ return config.expected("list or string", &key, value.clone());
+ }
+ }
// Then the build.rustflags value
let key = format!("build.{}", name);
- if let Some(args) = config.get_list(&key)? {
+ let list = config.get_list(&key);
+ if let Ok(Some(args)) = list {
let args = args.val.into_iter().map(|a| a.0);
return Ok(args.collect());
- } else if let Some(arg) = config.get_string(&key)? {
+ }
+ let string = config.get_string(&key);
+ if let Ok(Some(arg)) = string {
return Ok(arg.val.split(' ').map(str::to_string).collect());
}
+ if list.is_err() && string.is_err() {
+ if let Some(value) = config.values()?.get(&key) {
+ return config.expected("list or string", &key, value.clone());
+ }
+ }
Ok(Vec::new())
}
assert_that(p.cargo("bench"),
execs().with_status(101));
}
+
+#[test]
+fn target_rustflags_string_and_array_form1() {
+ let p1 = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ "#)
+ .file("src/lib.rs", "")
+ .file(".cargo/config", r#"
+ [build]
+ rustflags = ["--cfg", "foo"]
+ "#);
+ p1.build();
+
+ assert_that(p1.cargo("build").arg("-v"),
+ execs().with_status(0).with_stderr("\
+[COMPILING] foo v0.0.1 ([..])
+[RUNNING] `rustc [..] --cfg foo[..]`
+[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
+"));
+
+ let p2 = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ "#)
+ .file("src/lib.rs", "")
+ .file(".cargo/config", r#"
+ [build]
+ rustflags = "--cfg foo"
+ "#);
+ p2.build();
+
+ assert_that(p2.cargo("build").arg("-v"),
+ execs().with_status(0).with_stderr("\
+[COMPILING] foo v0.0.1 ([..])
+[RUNNING] `rustc [..] --cfg foo[..]`
+[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
+"));
+
+}
+
+#[test]
+fn target_rustflags_string_and_array_form2() {
+ let p1 = project("foo")
+ .file("Cargo.toml", &format!(r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+
+ [target.{}]
+ rustflags = ["--cfg", "foo"]
+ "#, rustc_host()))
+ .file("src/lib.rs", "");
+ p1.build();
+
+ assert_that(p1.cargo("build").arg("-v"),
+ execs().with_status(0).with_stderr("\
+[COMPILING] foo v0.0.1 ([..])
+[RUNNING] `rustc [..] --cfg foo[..]`
+[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
+"));
+
+ let p2 = project("foo")
+ .file("Cargo.toml", &format!(r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+
+ [target.{}]
+ rustflags = "--cfg foo"
+ "#, rustc_host()))
+ .file("src/lib.rs", "");
+ p2.build();
+
+ assert_that(p2.cargo("build").arg("-v"),
+ execs().with_status(0).with_stderr("\
+[COMPILING] foo v0.0.1 ([..])
+[RUNNING] `rustc [..] --cfg foo[..]`
+[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
+"));
+
+}